from src.enums.exception import ExceptionEnum
from src.enums.task import TaskStatusEnum
from starlette import status

# api接口响应异常
class ResponseException(Exception):
    def __init__(self, status_code: int,error: ExceptionEnum):
        self.status_code = status_code
        self.error_code = error.code
        self.message = error.msg

# 应用异常
class ApplicationException(ResponseException):
    def __init__(self, error: ExceptionEnum):
        super().__init__(status_code = status.HTTP_200_OK, error = error)

# 任务异常
class TaskException(Exception):
    def __init__(self,task_status: TaskStatusEnum, error: ExceptionEnum):
        self.task_status = task_status
        self.reason = "[" + error.code + "]" + error.msg

# 任务完成异常
class TaskFinishException(TaskException):
    def __init__(self,error: ExceptionEnum):
        self.task_status = TaskStatusEnum.FINISH
        self.reason = "[" + error.code + "]" + error.msg

# 任务延期执行异常
class TaskDelayException(TaskException):
    def __init__(self,error: ExceptionEnum):
        self.task_status = TaskStatusEnum.ABNORMAL_DELAY
        self.reason = "[" + error.code + "]" + error.msg

# 任务失败异常
class TaskFailureException(TaskException):
    def __init__(self,error: ExceptionEnum):
        self.task_status = TaskStatusEnum.FAILURE
        self.reason = "[" + error.code + "]" + error.msg
